import sys
import os

from PyQt4 import QtCore, QtGui

from browsepane import *
from fontpreview import *

class MainUi(QtGui.QWidget):
	def __init__(self, parent=None):
		QtGui.QWidget.__init__(self, parent)
		self.layout = QtGui.QHBoxLayout(self)
		self.setLayout(self.layout)
		self.bp = BrowsePane(self)
		self.layout.addWidget(self.bp)
		self.font_preview = QtGui.QWidget(self)
		self.font_preview = FontPreviewWidget()
		self.font_preview.sampleText = "Sample text"
		self.font_preview.sampleSize = 50
		self.layout.addWidget(self.font_preview)
		self.connect(self.bp.fontsView, QtCore.SIGNAL("pressed (const QModelIndex &)"), self.refresh_preview)
	
	def refresh_preview(self, index):
		if not index.isValid() or index.column() != 1:
			return
		self.font_preview.hide()
		self.font_preview.fontFile = os.path.join(self.bp.fontsView.model.folder, index.internalPointer().data(index.column()))
		self.font_preview.show()
		
	
if __name__ == '__main__':
	app = QtGui.QApplication(sys.argv)
	window = MainUi()
	window.show()
	app.exec_()